/**
 * Created by winter on 2017-02-20.
 */
/*(function (angular) {
  "use strict";*/

  /*angular.module('app')
    .service('paginationService', paginationService);*/

  /** @ngInject */
  module.exports = function () {
    var service = {
      setPageSetting: setPageSetting,
      getDefaultPageSetting: getDefaultPageSetting,
      addPageSettingForRequest: addPageSettingForRequest
    };
    return service;

    /**
     * 获取列表后设置分页信息
     * @param pageNo
     * @param pageSize
     * @param totalItems
     * @returns {{pageNo: *, pageSize: *, totalItems: *}}
     */
    function setPageSetting(pageNo, pageSize, totalItems) {
      var pageSetting = {
        pageNo: pageNo + 1,//当前页，前端起始页从1开始
        pageSize: pageSize,
        totalItems: totalItems
      };
      return pageSetting;
    }

    /**
     * 默认分页信息
     * @returns {{pageNo: number, pageSize: number, totalItems: number, maxSize: number}}
     */
    function getDefaultPageSetting() {
      var pageSetting = {
        pageNo: 1,
        pageSize: 10,
        totalItems: 10,
        maxSize: 8
      };
      return pageSetting;
    }

    function addPageSettingForRequest(params, pageSetting) {
      var requestParams = params;
      //yuedong 确认所有的列表分页 都是以begin命名 begin代表偏移量
      // requestParams.pageNo = pageSetting.pageNo - 1;
      requestParams.begin = (pageSetting.pageNo - 1) * pageSetting.pageSize;
      requestParams.pageSize = pageSetting.pageSize;
      return requestParams;
    }
  }

/*})(angular);*/
